package com.cre_drt;

import java.io.IOException;
import java.io.InputStream;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.Window;


public class EasterEggActivity extends Activity {	

	BackgroundSound mBackgroundSound;
	MediaPlayer player;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
	    getActionBar().hide();
	    
	    InputStream stream = null; 
	    try { 
	    	stream = getAssets().open("dancing_banana.gif"); 
	    } 
	    catch (IOException e) { 
	    	e.printStackTrace(); 
	    } 
	    
	    EasterEgg view = new EasterEgg(this, stream); 
	    setContentView(view);
	    
	    mBackgroundSound = new BackgroundSound();
	    player = MediaPlayer.create(EasterEggActivity.this, R.raw.pbjt);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		// getMenuInflater().inflate(R.menu.easter_egg, menu);
		return true;
	}
	
	public class BackgroundSound extends AsyncTask<Void, Void, Void> {

	    @Override
	    protected Void doInBackground(Void... params) {	         
	        player.setLooping(true); // Set looping 
	        player.setVolume(100,100); 
	        player.start(); 

	        return null;
	    }
	}
	
	public void onResume() {
		super.onResume();
		mBackgroundSound.execute();
	}
	
	public void onDestroy() {
		super.onDestroy();
		player.stop();
		mBackgroundSound.cancel(true);
	}
}
